﻿using Newtonsoft.Json;
using System.Text.Encodings.Web;
using System.Text.Unicode;

namespace DFGJ.WMS_PDA.WebAPI.Extensions
{  
    /// <summary>
    /// ControllerS扩展
    /// </summary>
    public static class ControllersExtend
    {

        /// <summary>
        ///  注入Controllers
        /// </summary>
        /// <param name="builder"></param>
        public static void AddControllerSetUp(this WebApplicationBuilder builder) 
        {
            builder.Services.AddControllers(option =>
            {
                 

            }).AddNewtonsoftJson(options =>
            {
                //配置返回JSON首字母问题以及格式
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
                //options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();//设置JSON返回格式同model一致

                options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();//设置JSON返回格式首字母小写


            }).AddJsonOptions(options =>
            {
                //配置解决中文乱码问题
                options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
            }); ;

        }


    }  


}
